﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using NPOI.SS.UserModel;
using System.IO;
using NPOI.XSSF.UserModel;
using NPOI.HSSF.UserModel;
using yncTech.Common;
using yncTech.BusinessObjects;
using System.Globalization;
using System.Text;
using System.Data.OleDb;
using System.Collections;

using EntitySpaces.Interfaces;

public partial class Admin_SAPFin_SAPFin003a : AdminBasePage
{
    decimal ? Id;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["Id"] != null)
        {
            Id = decimal.Parse(Request.QueryString["Id"]);
        }
        if ((!IsPostBack) && (Id.HasValue))
        {
            FinReceipt finReceipt=new FinReceipt();
            if (finReceipt.LoadByPrimaryKey(Id.Value))
            {
                txtDocumentsNo.Text= finReceipt.DocumentsNo;
                txtReference.Text = finReceipt.Reference;
                txtReferenceKey.Text = finReceipt.ReferenceKey;
                txtDocumentHeaderText.Text = finReceipt.DocumentHeaderText;
                txtPostingDate.Text =finReceipt.PostingDate.HasValue? finReceipt.PostingDate.Value.ToString("yyyy-MM-dd"):"";
                txtCompanyName.Text = finReceipt.CompanyName;
                txtCompanyCode.Text = finReceipt.CompanyCode;
                txtFunctionDept.Text = Business.getCodeTableValue(finReceipt.FunctionDept);
                txtVoucherDescription.Text = Business.getCodeTableValue(finReceipt.VoucherDescription);
                txtDocumentDate.Text = finReceipt.DocumentDate.HasValue ? finReceipt.DocumentDate.Value.ToString("yyyy-MM-dd") : "";
                txtLogicalSystem.Text = finReceipt.LogicalSystem;
                txtDocumentSystem.Text = finReceipt.DocumentSystem;
                txtReferenceTransact.Text = finReceipt.ReferenceTransact;
                txtUserName.Text = finReceipt.UserName;
                txtDocumentsType.Text = Business.getCodeTableValue(finReceipt.DocumentsType);
                txtRevesedBy.Text = finReceipt.RevesedBy;
                txtComments.Text = finReceipt.Comments;
                txtStoreStatus.Text = Business.getCodeTableValue(finReceipt.StorageStatus);
                txtEStoreStatus.Text = Business.getCodeTableValue(finReceipt.EStorageStatus);
                txtEStoreLocation.Text = finReceipt.EStorageLocation;
                BFThirdUnit bFThirdUnit = new BFThirdUnit();
                bFThirdUnit.LoadByPrimaryKey(finReceipt.StorageLocation.Value);
                txtStoreLocation.Text += bFThirdUnit.Name;
                if (finReceipt.ThirdUnitCabinId.HasValue)
                {
                    BFThirdUnitCabin bFThirdUnitCabin = new BFThirdUnitCabin();
                    if (bFThirdUnitCabin.LoadByPrimaryKey(finReceipt.ThirdUnitCabinId.Value))
                    {
                        txtStoreLocation.Text += bFThirdUnitCabin.Name;
                    }
                }
                if (finReceipt.ThirdUnitNumberId.HasValue)
                {
                    BFThirdUnitNumber bFThirdUnitNumber = new BFThirdUnitNumber();
                    if (bFThirdUnitNumber.LoadByPrimaryKey(finReceipt.ThirdUnitNumberId.Value))
                    {
                        txtStoreLocation.Text += bFThirdUnitNumber.Name;
                    }
                }

                if (finReceipt.BoxID.HasValue && finReceipt.BoxID.Value > 0)
                {
                    FinBox finBox = new FinBox();
                    if (finBox.LoadByPrimaryKey(finReceipt.BoxID.Value))
                    {
                        txtBoxNo.Text = finBox.BoxNo;
                        txtSupplierBoxNo.Text = finBox.SupplierBoxNo;
                    }
                }
            }
        }
    }



    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (Id.HasValue)
        {
            FinReceipt finReceipt = new FinReceipt();
            if (finReceipt.LoadByPrimaryKey(Id.Value))
            {
                finReceipt.IsConfirmed = true;
                finReceipt.ConfirmedBy = LoginUserInfo.CurrentUser.UserName;
                finReceipt.ConfirmedDttm = DateTime.Now;
                finReceipt.Save();
            }
        }
        WebHelper.CloseDialog(true);

    }
    protected void btnClose_Click(object sender, EventArgs e)
    {
        WebHelper.CloseDialog(true);
    }

}